import { WelfareItem } from "./WelfareItem";
import { SAttribute } from "../../../../../Message/Public/SAttribute";
import { Language } from "../../../../../extend/language/Language";
import { LoadRewardConfig } from "../../../resource/LoadRewardConfig";
import { ItemData } from "../../../resource/info/ItemData";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { ColorConfig } from "../../../resource/ColorConfig";
import { Cache } from "../../../cache/Cache";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { EventName } from "../../../mvc/EventName";
import { DataEvent } from "../../../events/DataEvent";
import { Alert } from "../../../../../com/mui/controls/Alert";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { BaseItem } from "../../common/BaseItem";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { TLoadReward } from "../../../../../Message/Db/Tables/TLoadReward";
type int = number;
//class WelfareLoginItem
    
    export  class WelfareLoginItem extends WelfareItem
    {
        constructor()
        {
            super();
            addEventListener(flash.events.Event.REMOVED_FROM_STAGE, this.onRemoveFromStage);
            return;
        }

        public updateData(arg1: SAttribute): void
        {
            var loc1=0;
            var loc2=0;
            var loc3=null;
            var loc4=null;
            if (!arg1) 
            {
                return;
            }
            _titleTxt2.text = Language.getStringByParam(20562, arg1.value) + "：";
            this._rewardDay = parseInt(arg1.valueStr);
            if (this._rewardDay > 0) 
            {
                if (this._rewardDay % 60 != 0) 
                {
                    this._rewardDay = this._rewardDay % 60;
                }
                else 
                {
                    this._rewardDay = 60;
                }
                loc1 = this._rewardDay;
                this._tLoadReward = LoadRewardConfig.instance.getLoadRewardByDay(this._rewardDay);
            }
            else 
            {
                loc2 = LoadRewardConfig.instance.getNextRewardByDay(arg1.value);
                loc1 = loc2;
                this._tLoadReward = LoadRewardConfig.instance.getLoadRewardByDay(loc2);
            }
            this._extTxt1.text = Language.getStringByParam(20568, loc1) + "：";
            this._extTxt2.text = Language.getStringByParam(20570, loc1) + "：";
            if (this._tLoadReward != null) 
            {
                loc3 = this._tLoadReward.rewardNotRecharge.split(",");
                loc4 = new ItemData(parseInt(loc3[0]));
                this._item1.itemData = loc4;
                this._item1.setAmountText(parseInt(loc3[1]));
                this._itemName1.htmlText = HTMLUtil.addColor(loc3[1] + Language.getString(20563), GlobalStyle.color1) + HTMLUtil.addColor(loc4.itemInfo.item.name, ColorConfig.instance.getItemColor(loc4.itemInfo.item.color).color);
                loc3 = this._tLoadReward.rewardRecharge.split(",");
                loc4 = new ItemData(parseInt(loc3[0]));
                this._item2.itemData = loc4;
                this._item2.setAmountText(parseInt(loc3[1]));
                this._itemName2.htmlText = HTMLUtil.addColor(loc3[1] + Language.getString(20563), GlobalStyle.color1) + HTMLUtil.addColor(loc4.itemInfo.item.name, ColorConfig.instance.getItemColor(loc4.itemInfo.item.color).color);
            }
            if (this._rewardDay <= 0) 
            {
                this._expGetBtn1.enabled = false;
                this._expGetBtn2.enabled = false;
            }
            if (Cache.instance.role.recharge > 0) 
            {
                this._expGetBtn2.label = Language.getString(20564);
                this._expGetBtn1.enabled = false;
                if (this._rewardDay > 0) 
                {
                    this._expGetBtn2.enabled = true;
                }
            }
            else 
            {
                Dispatcher.addEventListener(EventName.HavePay, this.onPlayerHavePayHandler);
                this._expGetBtn2.label = Language.getString(20565);
                this._expGetBtn2.enabled = true;
                if (this._rewardDay > 0) 
                {
                    this._expGetBtn1.enabled = true;
                }
            }
            return;
        }

        /* internal  */onRemoveFromStage(arg1: Object /* flash.events.Event */): void
        {
            Dispatcher.removeEventListener(EventName.HavePay, this.onPlayerHavePayHandler);
            return;
        }

        /* internal  */onPlayerHavePayHandler(arg1: DataEvent): void
        {
            this._expGetBtn2.label = Language.getString(20564);
            if (this._rewardDay > 0) 
            {
                this._expGetBtn2.enabled = true;
            }
            this._expGetBtn1.enabled = false;
            Dispatcher.removeEventListener(EventName.HavePay, this.onPlayerHavePayHandler);
            return;
        }

        /* internal  */onExp1GetBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.SeriesLoginGainReward, this._rewardDay));
            return;
        }

        /* internal  */onExp2GetBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._expGetBtn2.label != Language.getString(20564)) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.GotoPay));
            }
            else 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.SeriesLoginGainReward, this._rewardDay));
            }
            return;
        }

        /* internal  */onClearDayLinkHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            Alert.show(Language.getString(20566), null, Alert.OK | Alert.CANCEL, null, this.onAlertCloseHandler);
            return;
        }

        /* internal  */onAlertCloseHandler(arg1: int): void
        {
            if (arg1 == Alert.OK) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.SeriesLoginClearDay));
            }
            return;
        }

        /* internal  */onShowAllLinkHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.SeriesLoginLookupReward));
            return;
        }

        protected /* override */ initUI(): void
        {
            super.initUI();
            _titleTxt.text = Language.getString(20567);
            this._extTxt1 = new Object /* flash.text.TextField */();
            this._extTxt1.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._extTxt1.textColor = GlobalStyle.color1Uint;
            this._extTxt1.text = Language.getStringByParam(20568, 0) + "：";
            this._extTxt1.width = 130;
            this._extTxt1.height = 18;
            this._extTxt1.mouseEnabled = false;
            this._extTxt1.x = 5;
            this._extTxt1.y = _titleBg2.y + _titleBg2.height + 8;
            addChild(this._extTxt1);
            var loc1=ObjCreate.createBitmap(ImagesConst.PackItemBg, 8, this._extTxt1.y + this._extTxt1.textHeight + 3, this);
            this._item1 = new BaseItem();
            this._item1.setSize(33, 33);
            this._item1.x = loc1.x + 2;
            this._item1.y = loc1.y + 2;
            addChild(this._item1);
            this._itemName1 = new Object /* flash.text.TextField */();
            this._itemName1.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._itemName1.text = Language.getString(20569);
            this._itemName1.width = 100;
            this._itemName1.height = 18;
            this._itemName1.mouseEnabled = false;
            this._itemName1.x = 55;
            this._itemName1.y = this._item1.y + (this._item1.height - this._itemName1.textHeight) / 2;
            addChild(this._itemName1);
            this._expGetBtn1 = new GButton();
            this._expGetBtn1.label = Language.getString(20564);
            this._expGetBtn1.setSize(44, 20);
            this._expGetBtn1.styleName = "Button";
            this._expGetBtn1.x = width - this._expGetBtn1.width - 10;
            this._expGetBtn1.y = this._itemName1.y;
            this._expGetBtn1.textField.filters = [FilterConst.glowFilter];
            this._expGetBtn1.addEventListener(flash.events.MouseEvent.CLICK, this.onExp1GetBtnClickHandler);
            addChild(this._expGetBtn1);
            this._line = GlobalClass.getBitmap(ImagesConst.SplitLine);
            this._line.x = 10;
            this._line.y = 118;
            this._line.width = width - 20;
            addChild(this._line);
            this._extTxt2 = new Object /* flash.text.TextField */();
            this._extTxt2.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._extTxt2.textColor = GlobalStyle.color1Uint;
            this._extTxt2.text = Language.getStringByParam(20570, 0) + "：";
            this._extTxt2.width = 130;
            this._extTxt2.height = 18;
            this._extTxt2.mouseEnabled = false;
            this._extTxt2.x = 5;
            this._extTxt2.y = this._line.y + 4;
            addChild(this._extTxt2);
            loc1 = ObjCreate.createBitmap(ImagesConst.PackItemBg, 8, this._extTxt2.y + this._extTxt2.textHeight + 3, this);
            this._item2 = new BaseItem();
            this._item2.setSize(33, 33);
            this._item2.x = loc1.x + 2;
            this._item2.y = loc1.y + 2;
            addChild(this._item2);
            this._itemName2 = new Object /* flash.text.TextField */();
            this._itemName2.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._itemName2.text = Language.getString(20569);
            this._itemName2.width = 100;
            this._itemName2.height = 18;
            this._itemName2.mouseEnabled = false;
            this._itemName2.x = 55;
            this._itemName2.y = this._item2.y + (this._item2.height - this._itemName2.textHeight) / 2;
            addChild(this._itemName2);
            this._expGetBtn2 = new GButton();
            this._expGetBtn2.label = Language.getString(20564);
            this._expGetBtn2.setSize(44, 20);
            this._expGetBtn2.styleName = "Button";
            this._expGetBtn2.x = width - this._expGetBtn2.width - 10;
            this._expGetBtn2.y = this._itemName2.y;
            this._expGetBtn2.addEventListener(flash.events.MouseEvent.CLICK, this.onExp2GetBtnClickHandler);
            this._expGetBtn2.textField.filters = [FilterConst.glowFilter];
            addChild(this._expGetBtn2);
            this._clearDay = new Object /* flash.text.TextField */();
            this._clearDay.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._clearDay.filters = [FilterConst.glowFilter];
            this._clearDay.htmlText = "<u><a href=\'event: 0\'>" + HTMLUtil.addColor(Language.getString(20571), "#FFA700") + "</a></u>";
            this._clearDay.width = 55;
            this._clearDay.height = 18;
            this._clearDay.x = 54;
            this._clearDay.y = height - this._clearDay.textHeight - 5;
            this._clearDay.addEventListener(flash.events.TextEvent.LINK, this.onClearDayLinkHandler);
            addChild(this._clearDay);
            this._showAll = new Object /* flash.text.TextField */();
            this._showAll.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._showAll.filters = [FilterConst.glowFilter];
            this._showAll.htmlText = "<u><a href=\'event: 0\'>" + HTMLUtil.addColor(Language.getString(20572), "#00ff00") + "</a></u>";
            this._showAll.width = 100;
            this._showAll.height = 18;
            this._showAll.x = 115;
            this._showAll.y = this._clearDay.y;
            this._showAll.addEventListener(flash.events.TextEvent.LINK, this.onShowAllLinkHandler);
            addChild(this._showAll);
            return;
        }

        /* internal */ /* var */_extTxt1: Object /* flash.text.TextField */;

        /* internal */ /* var */_item1: BaseItem;

        /* internal */ /* var */_itemName1: Object /* flash.text.TextField */;

        /* internal */ /* var */_expGetBtn1: GButton;

        /* internal */ /* var */_line: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_extTxt2: Object /* flash.text.TextField */;

        /* internal */ /* var */_item2: BaseItem;

        /* internal */ /* var */_itemName2: Object /* flash.text.TextField */;

        /* internal */ /* var */_expGetBtn2: GButton;

        /* internal */ /* var */_clearDay: Object /* flash.text.TextField */;

        /* internal */ /* var */_showAll: Object /* flash.text.TextField */;

        /* internal */ /* var */_rewardDay: int;

        /* internal */ /* var */_tLoadReward: TLoadReward;
    }
